package wps.util {
import flash.geom.Point;

public class MathUtil {

    public static const DEGREES_FACTOR:Number = Math.PI / 180;

    /**
     * 正弦
     *
     * @param x 角度数。如：sin(30) = 0.5
     */
    public static function sin(x:Number):Number {
        return Math.sin(x * DEGREES_FACTOR);
    }

    /**
     * 余弦
     *
     * @param x 角度数。如：cos(60) = 0.5
     */
    public static function cos(x:Number):Number {
        return Math.cos(x * DEGREES_FACTOR);
    }

    /**
     * 获得一个矩形旋转后的左上角坐标
	 * 只能用于BasicLayout，而且没有设置horizontalCenter和verticalCenter
     *
     * @param x 左上角X坐标
     * @param y 左上角Y坐标
     * @param w 矩形宽度
     * @param h 矩形长度
     * @param d 顺时针旋转的角度
     *
     * @return 旋转后的左上角坐标
     */
    public static function getPointRotated(x:Number, y:Number, w:Number, h:Number, d:Number):Point {
        var xn:Number = -(w / 2);
        var yn:Number = -(h / 2);
        var degrees:Number = -d;

        var xx:Number = xn * MathUtil.cos(degrees) + yn * MathUtil.sin(degrees);
        var yy:Number = yn * MathUtil.cos(degrees) - xn * MathUtil.sin(degrees);

        return new Point(xx + x + w / 2, yy + y + h / 2);
    }

}

}
